package com.usian.controller;

import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.usian.common.vo.GeoVo;

/**
 * @TODO:
 * @Author:baimu
 * @Date:2025 03 04 09 11
 **/
public class AmapController {


    public static void main(String[] args) {

        //定义接口的路径
        String url="https://restapi.amap.com/v3/geocode/geo?address=北京市朝阳区阜通东大街6号&output=JSON&key=44a9d8cc27ee95befaf652dc84e36f30";
        //使用hutool 发起get请求, 调用接口
        String s = HttpUtil.get(url);
        //打印结果:{"status":"1","info":"OK","infocode":"10000","count":"2","geocodes":[{"formatted_address":"北京市朝阳区阜通东大街6号","country":"中国","province":"北京市","citycode":"010","city":"北京市","district":"朝阳区","township":[],"neighborhood":{"name":[],"type":[]},"building":{"name":[],"type":[]},"adcode":"110105","street":"阜通东大街","number":"6号","location":"116.482086,39.990496","level":"门址"},{"formatted_address":"北京市朝阳区阜通东大街6号院","country":"中国","province":"北京市","citycode":"010","city":"北京市","district":"朝阳区","township":[],"neighborhood":{"name":[],"type":[]},"building":{"name":[],"type":[]},"adcode":"110105","street":"阜通东大街","number":"6号院","location":"116.482145,39.990039","level":"门址"}]}
        System.out.println(s);//json字符串

        //解析json:获取经纬度
        GeoVo geoVo = JSON.parseObject(s, GeoVo.class);

        System.out.println(geoVo.getStatus());
        System.out.println(geoVo.getInfo());
        System.out.println(geoVo.getInfocode());

    }


}
